package threadx;

public class ThreadLocalNormalUsage06 {
    public static void main(String[] args) {
        new service1().process();
    }
}

class service1 {
    public void process() {
        User user = new User("鲁毅");
        UserContextHolder.holder.set(user);
        new service2().process();
    }
}

class service2 {
    public void process() {
        User user = UserContextHolder.holder.get();
        System.out.println("Service2拿到用户名：" + user.name);
        new service3().process();
    }
}

class service3 {
    public void process() {
        User user = UserContextHolder.holder.get();
        System.out.println("Service3拿到用户名：" + user.name);
    }
}

class UserContextHolder {
    public static ThreadLocal<User> holder = new ThreadLocal<>();
}

class User {
    String name;

    public User(String name) {
        this.name = name;
    }
}